﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ePlanet.ArchiveMange.Services;
using DreamBuilder.Core.Container;
using ePlanet.ArchiveMange.Enum;
using System.Collections;

namespace Web.Views.DataManage
{
    public partial class ArchiveCodeRangePrintView : System.Web.UI.Page
    {

        /// <summary>
        /// 文档类型ID
        /// </summary>
        public int ArchiveTypeID
        {
            get
            {
                int o_int = 0;
                if (Request.QueryString["archivetype"] != null)
                {
                    if (int.TryParse(Request.QueryString["archivetype"], out o_int))
                    {
                        return o_int;
                    }
                    else
                    {
                        throw new Exception("档案类型错误");
                    }
                }
                else
                {
                    throw new Exception("档案类型不能为空");
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 取区间内档号列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExecuteStatitics_Click(object sender, EventArgs e)
        {
            string startCode = txtStartCode.Value.Trim();
            string endCode = txtEndCode.Value.Trim();
            DataTable table = null;
            switch (ArchiveTypeID)
            {
                case (int)ArchiveBaseType.AudioVedio:
                    IAudioArchiveService audioService = UContainer.Resolve<IAudioArchiveService>();
                    table = audioService.GetDataIdByArchiveCodeRange(startCode, endCode);
                    break;
                case (int)ArchiveBaseType.CDKind:
                    ICDArchiveService cdService = UContainer.Resolve<ICDArchiveService>();
                    table = cdService.GetDataIdByArchiveCodeRange(startCode, endCode);
                    break;
                case (int)ArchiveBaseType.Document:
                    IDocumentArchiveService documentService = UContainer.Resolve<IDocumentArchiveService>();
                    table = documentService.GetDataIdByArchiveCodeRange(startCode, endCode);
                    break;
                case (int)ArchiveBaseType.RealKind:
                    IRealKindArchiveService realService = UContainer.Resolve<IRealKindArchiveService>();
                    table = realService.GetDataIdByArchiveCodeRange(startCode, endCode);
                    break;
                case (int)ArchiveBaseType.OliSearch:
                    IZongheVolService oilService = UContainer.Resolve<IZongheVolService>();
                    table = oilService.GetDataIdByArchiveCodeRange(startCode, endCode);
                    break;

            }
            if (table == null || table.Rows.Count == 0)
            {
                this.RegisterClientScriptBlock("alert",
                string.Format("<script>alert('没有可打印的数据！');window.close();</script>"
                , (int)ArchiveTypeID));
            }
            else
            {
                ArrayList dataIdList = new ArrayList();
                foreach (DataRow item in table.Rows)
                {
                    dataIdList.Add(item["dataid"]);
                }
                Session["sjgl_hnml_selectedkeys"] = dataIdList;
                this.RegisterClientScriptBlock("alert",
                string.Format("<script>window.location.href='../ArchiveFlowView/PrintBoxCatagoryView.aspx?from=sjgl&archiveType={0}';</script>"
                , (int)ArchiveTypeID));
                //this.Response.Redirect(string.Format("", ArchiveTypeID));
            }
        }
    }
}